#!/bin/bash
# 需更改hosts地址

# 设置hosts
echo "192.168.248.131 vm1" >> /etc/hosts
echo "192.168.248.132 vm2" >> /etc/hosts
echo "192.168.248.133 vm3" >> /etc/hosts
echo "199.232.4.133 raw.githubusercontent.com" >> /etc/hosts

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables
	
# 关闭selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 关闭swap分区
swapoff -a  && sysctl -w vm.swappiness=0
sed -i '/ swap /s/^/#/ ' /etc/fstab

# 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce-cli-19.03.13-3.el7.x86_64 docker-ce-19.03.13-3.el7.x86_64
systemctl enable --now docker

# 配置镜像加速器、配置docker的cgroup控制器为systemd
cat > /etc/docker/daemon.json <<-EOF
{
  "registry-mirrors": ["https://886t0jcc.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker
    
# 将桥接的 IPv4 流量传递到 iptables 的链
cat > /etc/sysctl.d/k8s.conf <<-EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1         
EOF							
sysctl --system
	
# 安装ipset软件包和管理工具ipvsadm
yum -y install ipvsadm ipset

# 配置时间同步
yum -y install ntpdate
ntpdate ntp.aliyun.com